package com.aspose.cells;

class zff {
   static int a(char[] var0) {
      int var1 = 0;

      for(int var2 = 0; var2 < var0.length; ++var2) {
         var1 += a(var0[var2]);
      }

      return var1;
   }

   static int a(char[] var0, int var1, int var2) {
      int var3;
      for(var3 = 0; var1 < var2; ++var1) {
         var3 += a(var0[var1]);
      }

      return var3;
   }

   static String a(String var0, int var1, int var2) {
      return var0.length() >= 1 && var2 >= 1 ? b(var0.toCharArray(), var1, var2) : "";
   }

   static String b(char[] var0, int var1, int var2) {
      if (var0.length >= 1 && var2 >= 1) {
         --var1;

         for(int var4 = 0; var4 < var0.length; ++var4) {
            int var3 = a(var0[var4]);
            var1 -= var3;
            if (var1 < 0) {
               char var5 = var0[var4];
               if (var3 == 1) {
                  if (var2 < 2) {
                     return Character.toString(var0[var4]);
                  }

                  --var2;
               } else {
                  if (var2 < 2) {
                     return " ";
                  }

                  if (var1 == -2) {
                     if (var2 < 3) {
                        return Character.toString(var0[var4]);
                     }

                     var2 -= 2;
                  } else {
                     var5 = ' ';
                     --var2;
                  }
               }

               StringBuilder var6 = new StringBuilder(var2);
               var6.append(var5);
               ++var4;

               while(var4 < var0.length) {
                  var2 -= a(var0[var4]);
                  if (var2 < 0) {
                     var6.append(' ');
                     return com.aspose.cells.b.a.zr.a(var6);
                  }

                  var6.append(var0[var4]);
                  if (var2 == 0) {
                     return com.aspose.cells.b.a.zr.a(var6);
                  }

                  ++var4;
               }

               return com.aspose.cells.b.a.zr.a(var6);
            }
         }

         return "";
      } else {
         return "";
      }
   }

   static String a(String var0, int var1) {
      char[] var2 = var0.toCharArray();
      int var3 = a(var2);
      return var3 < var1 ? var0 : a(var0, var3 - var1 + 1, var1);
   }

   static String a(String var0, int var1, int var2, String var3) {
      StringBuilder var4 = new StringBuilder(var0.length() + var3.length());
      char[] var5 = var0.toCharArray();
      --var1;

      for(int var7 = 0; var7 < var5.length; ++var7) {
         int var6 = a(var5[var7]);
         var1 -= var6;
         if (var1 < 0) {
            if (var6 == 1) {
               --var2;
            } else if (var1 == -2) {
               var2 -= 2;
            } else {
               var4.append(' ');
               --var2;
            }

            if (var2 <= 0) {
               if (var2 < 0) {
                  var4.append(' ');
               }

               var4.append(var3);
               var4.append(var5, var7 + 1, var5.length - var7 - 1);
               return com.aspose.cells.b.a.zr.a(var4);
            }

            ++var7;

            while(var7 < var5.length) {
               var2 -= a(var5[var7]);
               if (var2 <= 0) {
                  if (var2 < 0) {
                     var4.append(' ');
                  }

                  var4.append(var3);
                  var4.append(var5, var7 + 1, var5.length - var7 - 1);
                  return com.aspose.cells.b.a.zr.a(var4);
               }

               ++var7;
            }
         } else {
            var4.append(var5[var7]);
         }
      }

      var4.append(var3);
      return com.aspose.cells.b.a.zr.a(var4);
   }

   static zagu a(String var0, String var1, int var2) {
      if (var2 >= var1.length()) {
         return zzg.a;
      } else {
         if (com.aspose.cells.b.a.zv.a(var0, new char[]{'?', '*'}) != -1) {
            var0 = com.aspose.cells.b.a.zv.a(var0, "?", ".?");
            var0 = com.aspose.cells.b.a.zv.a(var0, "*", ".*");
            if (var2 != 0) {
               var1 = var1.substring(var2);
            }

            com.aspose.cells.b.a.g.a.zc var3 = com.aspose.cells.b.a.g.a.ze.a(var1.toUpperCase(), var0.toUpperCase());
            if (var3.c()) {
               return new zyy((double)var3.d() + 1.0D);
            }
         } else {
            int var4 = var1.toUpperCase().indexOf(var0.toUpperCase(), var2);
            if (var4 > -1) {
               return new zyy((double)var4 + 1.0D);
            }
         }

         return zzg.a;
      }
   }

   static zagu b(String var0, String var1, int var2) {
      char[] var3 = var0.toCharArray();
      char[] var4 = var1.toCharArray();
      if (var2 + a(var3) - 1 > a(var4)) {
         return zzg.a;
      } else if (var3.length == 0) {
         return new zyy((double)var2);
      } else {
         int var5 = var4.length;
         int var6 = var3.length;
         int[] var7 = new int[var6];
         --var6;
         int var8 = 0;
         int var9 = -1;
         var7[0] = -1;

         while(true) {
            while(var8 < var6) {
               if (var9 != -1 && var3[var9] != '?' && var3[var8] != var3[var9]) {
                  var9 = var7[var9];
               } else {
                  ++var8;
                  ++var9;
                  var7[var8] = var9;
               }
            }

            ++var6;
            var8 = var2 - 1;
            var9 = 0;

            while(var8 < var5 && var9 < var6) {
               if (var9 != -1 && var3[var9] != '?' && var4[var8] != var3[var9]) {
                  var9 = var7[var9];
               } else {
                  ++var8;
                  ++var9;
               }
            }

            if (var9 >= var6) {
               return new zyy((double)(a((char[])var4, 0, var8 - var6) + 1));
            }

            return zzg.a;
         }
      }
   }

   static String a(String var0) {
      char[] var1 = var0.toCharArray();
      boolean var2 = false;

      for(int var4 = 0; var4 < var1.length; ++var4) {
         char var3 = var1[var4];
         if (Character.isLetter(var3)) {
            if (Character.isUpperCase(var3)) {
               if (var2) {
                  var1[var4] = Character.toLowerCase(var3);
               } else {
                  var1[var4] = var3;
               }
            } else if (Character.isLowerCase(var3)) {
               if (var2) {
                  var1[var4] = var3;
               } else {
                  var1[var4] = Character.toUpperCase(var3);
               }
            }

            var2 = true;
         } else {
            var2 = false;
         }
      }

      return new String(var1);
   }

   static String b(String var0) {
      if (var0.equals("")) {
         return var0;
      } else {
         int var1;
         int var2;
         char[] var3;
         boolean var4;
         if (var0.charAt(0) == ' ') {
            var3 = var0.toCharArray();
            var1 = 1;

            while(true) {
               if (var1 >= var3.length) {
                  return "";
               }

               if (var3[var1] != ' ') {
                  var3[0] = var3[var1];
                  var2 = 1;
                  ++var1;
                  var4 = false;
                  break;
               }

               ++var1;
            }
         } else if (var0.charAt(var0.length() - 1) == ' ') {
            var3 = var0.toCharArray();
            var1 = 1;

            while(true) {
               if (var3[var1++] == ' ') {
                  var2 = var1 - 1;
                  var4 = true;
                  break;
               }
            }
         } else {
            var2 = var0.indexOf("  ");
            if (var2 < 0) {
               return var0;
            }

            var1 = var2 + 2;
            var4 = true;
            var3 = var0.toCharArray();
         }

         for(; var1 < var3.length; ++var1) {
            if (var3[var1] == ' ') {
               var4 = true;
            } else {
               if (var4) {
                  var3[var2++] = ' ';
                  var4 = false;
               }

               var3[var2++] = var3[var1];
            }
         }

         if (var2 == var3.length) {
            return var0;
         } else {
            return new String(var3, 0, var2);
         }
      }
   }

   static String c(String var0) {
      char[] var1 = var0.toCharArray();
      int var2 = 0;
      boolean var3 = false;

      for(int var4 = 0; var4 < var1.length; ++var4) {
         if (var1[var4] > 31) {
            switch(var1[var4]) {
            case '\u007f':
            case '\u0081':
            case '\u008d':
            case '\u008f':
            case '\u0090':
            case '\u009d':
               var3 = true;
               break;
            default:
               if (var3) {
                  var1[var2] = var1[var4];
               }

               ++var2;
            }
         } else {
            var3 = true;
         }
      }

      if (var3) {
         return new String(var1, 0, var2);
      } else {
         return var0;
      }
   }

   static String a(int var0, int var1) {
      char[] var2 = new char[]{'M', 'D', 'C', 'L', 'X', 'V', 'I'};
      short var3 = 1000;
      char[] var4 = new char[256];
      int var7 = var3;
      int var6 = 0;

      int var5;
      for(var5 = 0; var7 > 1; var6 += 2) {
         do {
            if (var0 >= var7) {
               var4[var5++] = var2[var6];
               var0 -= var7;
            } else if (var0 >= var7 - var7 / 10) {
               var4[var5++] = var2[var6 + 2];
               var4[var5++] = var2[var6];
               var0 -= var7 - var7 / 10;
            } else if (var0 >= var7 / 2) {
               var4[var5++] = var2[var6 + 1];
               var0 -= var7 / 2;
            } else if (var0 >= var7 / 2 - var7 / 10) {
               var4[var5++] = var2[var6 + 2];
               var4[var5++] = var2[var6 + 1];
               var0 -= var7 / 2 - var7 / 10;
            } else {
               if (var7 != 10) {
                  break;
               }

               var4[var5++] = var2[var6 + 2];
               --var0;
            }
         } while(var0 > 0);

         if (var0 <= 0) {
            break;
         }

         var7 /= 10;
      }

      StringBuilder var8 = new StringBuilder(var5);
      var8.append(var4, 0, var5);
      if (var1 > 0) {
         com.aspose.cells.b.a.g.zf.a(var8, "XLV", "VL");
         com.aspose.cells.b.a.g.zf.a(var8, "XCV", "VC");
         com.aspose.cells.b.a.g.zf.a(var8, "CDL", "LD");
         com.aspose.cells.b.a.g.zf.a(var8, "CML", "LM");
         com.aspose.cells.b.a.g.zf.a(var8, "CMVC", "LMVL");
      }

      if (var1 == 1) {
         com.aspose.cells.b.a.g.zf.a(var8, "CDXC", "LDXL");
         com.aspose.cells.b.a.g.zf.a(var8, "CDVC", "LDVL");
         com.aspose.cells.b.a.g.zf.a(var8, "CMXC", "LMXL");
         com.aspose.cells.b.a.g.zf.a(var8, "XCIX", "VCIV");
         com.aspose.cells.b.a.g.zf.a(var8, "XLIX", "VLIV");
      }

      if (var1 > 1) {
         com.aspose.cells.b.a.g.zf.a(var8, "XLIX", "IL");
         com.aspose.cells.b.a.g.zf.a(var8, "XCIX", "IC");
         com.aspose.cells.b.a.g.zf.a(var8, "CDXC", "XD");
         com.aspose.cells.b.a.g.zf.a(var8, "CDVC", "XDV");
         com.aspose.cells.b.a.g.zf.a(var8, "CDIC", "XDIX");
         com.aspose.cells.b.a.g.zf.a(var8, "LMVL", "XMV");
         com.aspose.cells.b.a.g.zf.a(var8, "CMIC", "XMIX");
         com.aspose.cells.b.a.g.zf.a(var8, "CMXC", "XM");
      }

      if (var1 > 2) {
         com.aspose.cells.b.a.g.zf.a(var8, "XDV", "VD");
         com.aspose.cells.b.a.g.zf.a(var8, "XDIX", "VDIV");
         com.aspose.cells.b.a.g.zf.a(var8, "XMV", "VM");
         com.aspose.cells.b.a.g.zf.a(var8, "XMIX", "VMIV");
      }

      if (var1 == 4) {
         com.aspose.cells.b.a.g.zf.a(var8, "VDIV", "ID");
         com.aspose.cells.b.a.g.zf.a(var8, "VMIV", "IM");
      }

      return com.aspose.cells.b.a.zr.a(var8);
   }

   private static int a(char var0) {
      return var0 > 127 ? 2 : 1;
   }
}
